<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/25 0025
 * Time: 14:48
 */

namespace app\admin\controller;


use think\Controller;

class Banner extends Controller
{
    public function index(){
        $banner = db("banner")->select();
        $this->assign("banner",$banner);
        return view("index");
    }
    public function add(){
        if(request()->isAjax()){
            $file = request()->file('image');
            $info=$file->move( './static/images');
            $filename=str_replace("\\","/",$info->getSaveName());
            $image = '/static/images/'.$filename;
//            return $image;
            $data = [
                'image' => $image,
                'addtime' => date("Y-m-d H:i:s")
            ];
            $res = db("banner")->insert($data);
            if($res){
                return 200;
            }else{
                return -1;
            }
        }
        return view("add");
    }
    public function delete(){
        $id = input("id");
        $del = db("banner")->delete($id);
        if($del){
            return 200;
        }else{
            return -1;
        }
    }
}